package com.huluobo.a2204kotlinshopping.adapter

import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.gson.Gson
import com.huluobo.a2204kotlinshopping.R
import com.huluobo.base.bean.OrderBean
import com.huluobo.base.bean.OrderBeanList
import com.huluobo.base.bean.OrderType
import com.huluobo.base.bean.OrderTypeBean

/**
 *  Created by LC on 2024/8/6.
 */
class OrdersAdapter(list: MutableList<OrderTypeBean>) :
    BaseQuickAdapter<OrderTypeBean, BaseViewHolder>(R.layout.item_orders, list) {
    private lateinit var orderAdapter: OrderAdapter
    private val list = mutableListOf<OrderBean>()
    override fun convert(helper: BaseViewHolder, item: OrderTypeBean) {
        val typeString = when (item.type) {
            OrderType.PRE_PAY -> "待付款"
            OrderType.PAYED -> "已支付"
            OrderType.PRE_TAKE_OFF -> "待收货"
            OrderType.PRE_COMMENT -> "待评价"
        }
        helper.setText(R.id.item_orders_type_tv, typeString)
        val orderBeanList = Gson().fromJson(item.orders, OrderBeanList::class.java)//把Result中的Data转换为一个集合
        val rv = helper.getView<RecyclerView>(R.id.item_orders_rv)
        rv.layoutManager = LinearLayoutManager(context)
        orderAdapter = OrderAdapter(orderBeanList)
        rv.adapter = orderAdapter
    }
}